<template>
  <el-dropdown trigger="click" @command="handleCommand">
    <div class="right-menu">
      <el-tooltip
        class="box-item"
        :effect="effect"
        :content="$t('message.guide.langDesc')"
        placement="bottom"
      >
        <SvgIcon id="guide-lang" icon="language"></SvgIcon>
      </el-tooltip>
    </div>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item></el-dropdown-item>
        <el-dropdown-item></el-dropdown-item>
        <el-dropdown-item command="zh" :disabled="lang">中文</el-dropdown-item>
        <el-dropdown-item command="en" :disabled="!lang"
          >English</el-dropdown-item
        >
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>
<script setup>
import SvgIcon from '@/components/SvgIcon/index.vue'
import { useI18n } from 'vue-i18n'
import { computed, defineProps } from 'vue'
import { useStore } from 'vuex'
import { ElMessage } from 'element-plus'
const props = defineProps({
  effect: {
    type: String,
    default: 'dark',
    required: true
  }
})
const store = useStore()
const lang = computed(() => {
  return store.getters.lang === 'zh'
})
const effect = computed(() => {
  return props.effect === 'dark' ? 'dark' : 'light '
})
const I18n = useI18n()
const handleCommand = (command) => {
  I18n.locale.value = command
  store.commit('app/changeLanguage', command)
  ElMessage.success(I18n.t('message.toast.switchLangSuccess'))
}
</script>
